package com.itheima.object1;

public class StringCase {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3};
        String s = StringArr(arr);
        System.out.println(s);

    }

    private static String StringArr(int[] arr) {

        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            //第一种用三元运算符的方法
            //   String s = i == arr.length - 1 ? arr[i] + "]" : arr[i] + ",";
            //   sb.append(s);
            //第二种方法.
            if (i == arr.length - 1) {
                sb.append(arr[i] + "]");
            } else {
                sb.append(arr[i] + ",");
            }
        }
        return sb.toString();
    }

}
